<?php

/**
 * @author dragon.hu add @2016.3.9
 */
defined('BASEPATH') or die('forbidden');
require_once APPPATH.'channels/ChargeOrder.php';

class resupplyorder_controller extends Controller {

	private $inc;
	private $allchannel;
	private $platformList;
    function _init() {
        check_level(50, segment(0), segment(1), segment(2, 'index'));
        
        $this->inc = $this->config['inc'];
        $this->allchannel = $this->inc['allchannel'];
        $this->platformList = array('0' => 'IOS越狱', '1' => '安卓');
    }

    function index() {
     if (is_submit()) {
            $rowdata = $_POST['row'];
            //exit();
            
            //通过分期和角色名找到roleid
            /*$tmpconn = getTmpDbConnect(PLATFORM_ALL, 'all', $rowdata['area_host'], DBTYPE_GAMESERVER);
            $roleid = 0;
            if ($tmpconn)
            {
            	$sql = "SELECT id FROM player WHERE name='".$rowdata['role_name']."'";
            	$one = $tmpconn->one($sql);
            	$roleid = $one['id'];
            }
            else
            {
            	echo "<script>alert('connect database ".$rowdata['area_host']." failed')</script>";
            	return;
            }*/
            
            $orderLog = new ChargeOrder();
            $logstr = "订单补发  area_host:".$rowdata['area_host'].",select_platform:".$rowdata['select_platform'].",select_channel:".$rowdata['select_channel'].
            		",money:".$rowdata['money'].",role_name:".$rowdata['role_name'].",orderid:".$rowdata['orderid'];
            $orderLog->log($rowdata['select_channel'],$logstr);
            //进行发货(4表示补单成功，都是补单的情况)
            if(false == $orderLog->recordOrder(4, $rowdata['money'], $rowdata['orderid'], $rowdata['select_channel'], $rowdata['select_platform']))
            {
            	$result = 1;
            	$orderLog->log($rowdata['select_channel'],array("order"=>$rowdata['orderid'],"money"=>$rowdata['money'],"serverresult"=>"faild"));
            }else
            {
            	//支付成功
            	$result = 0;
            	$orderLog->log($rowdata['select_channel'],array("order"=>$rowdata['orderid'],"money"=>$rowdata['money'],"serverresult"=>"success"));
            }
            //$result=0;
            //操作失败
            if($result != 0)
            {
                //cp_tips("error");
            	echo "<script>alert('".translate('C_TIPS_ERROR_TEXT')."')</script>";
            }
            else
            {
            	//cp_tips("success");
            	echo "<script>alert('success！！！')</script>";
            }
            //echo $result;
            //cp_tips($result == 0 ? "success" : "error");
        }

        $data['row']=$rowdata;
        $this->view->assign("arealist", $this->form->select("row[area_host]", get_area_list_option(), '', array('id' => 'area_host')));
        $this->view->assign("channellist", $this->form->select("row[select_channel]", $this->allchannel, '', array('id' => 'select_channel')));
        $this->view->assign("platformlist", $this->form->select("row[select_platform]", $this->platformList, '', array('id' => 'select_platform')));
        $this->view->display("seal/resupplyorder/index",$data);
    }

}

?>
